package com.baidu.mapapi;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.location.Location;
import java.io.InputStream;

public class MyLocationOverlay extends Overlay
  implements SensorEventListener, LocationListener, Overlay.Snappable
{
  private Location a = null;
  private GeoPoint b = null;
  private GeoPoint c = null;
  private Runnable d = null;
  private MapView e = null;
  private Bitmap f = null;
  private Bitmap g = null;
  private Bitmap h = null;
  private boolean i = false;
  private boolean j = false;
  private float k = 0.0F;
  private Paint l = null;

  public MyLocationOverlay(Context paramContext, MapView paramMapView)
  {
    if (paramMapView == null)
      throw new IllegalArgumentException("mapView is null");
    this.e = paramMapView;
    this.l = new Paint();
    this.l.setARGB(35, 0, 0, 128);
    this.l.setStyle(Paint.Style.FILL_AND_STROKE);
    this.l.setAntiAlias(true);
    try
    {
      AssetManager localAssetManager = paramContext.getAssets();
      InputStream localInputStream1 = localAssetManager.open("icon_my.png");
      this.f = BitmapFactory.decodeStream(localInputStream1);
      localInputStream1.close();
      InputStream localInputStream2 = localAssetManager.open("compass_bg.png");
      this.g = BitmapFactory.decodeStream(localInputStream2);
      localInputStream2.close();
      InputStream localInputStream3 = localAssetManager.open("compass_pointer.png");
      this.h = BitmapFactory.decodeStream(localInputStream3);
      localInputStream3.close();
      return;
    }
    catch (Exception localException)
    {
    }
  }

  protected GeoPoint GetBaidu09Point(GeoPoint paramGeoPoint, int paramInt)
  {
    if (paramGeoPoint == null)
      return null;
    switch (paramInt)
    {
    default:
      return paramGeoPoint;
    case 0:
      return CoordinateConvert.bundleDecode(CoordinateConvert.fromWgs84ToBaidu(paramGeoPoint));
    case 1:
    }
    return CoordinateConvert.bundleDecode(CoordinateConvert.fromGcjToBaidu(paramGeoPoint));
  }

  public void disableCompass()
  {
    this.j = false;
    Mj.b.b(this);
    this.e.b.b = 0;
    this.e.invalidate();
  }

  public void disableMyLocation()
  {
    this.i = false;
    this.a = null;
    this.b = null;
    this.c = null;
    Mj.b.removeUpdates(this);
    this.e.invalidate();
  }

  protected boolean dispatchTap()
  {
    return false;
  }

  public boolean draw(Canvas paramCanvas, MapView paramMapView, boolean paramBoolean, long paramLong)
  {
    if (paramBoolean)
      return false;
    if ((this.a != null) && (this.b != null) && (this.c != null))
      drawMyLocation(paramCanvas, paramMapView, this.a, this.c, paramLong);
    if (this.j)
      drawCompass(paramCanvas, this.k);
    return true;
  }

  protected void drawCompass(Canvas paramCanvas, float paramFloat)
  {
    if ((paramFloat > 360.0F) || (paramFloat < -360.0F))
      return;
    paramCanvas.drawBitmap(this.g, 10, 10, null);
    int m = 10 + this.h.getWidth() / 2;
    int n = 10 + this.h.getHeight() / 2;
    Matrix localMatrix = new Matrix();
    localMatrix.postTranslate(10, 10);
    localMatrix.postRotate(-paramFloat, m, n);
    Paint localPaint = new Paint();
    localPaint.setAntiAlias(true);
    paramCanvas.drawBitmap(this.h, localMatrix, localPaint);
  }

  protected void drawMyLocation(Canvas paramCanvas, MapView paramMapView, Location paramLocation, GeoPoint paramGeoPoint, long paramLong)
  {
    if (paramGeoPoint == null);
    Point localPoint;
    do
    {
      return;
      localPoint = paramMapView.getProjection().toPixels(paramGeoPoint, null);
      int m = localPoint.x - this.f.getWidth() / 2;
      int n = localPoint.y - this.f.getHeight() / 2;
      paramCanvas.drawBitmap(this.f, m, n, null);
    }
    while (!paramLocation.hasAccuracy());
    float f1 = paramLocation.getAccuracy();
    float f2 = paramMapView.getProjection().metersToEquatorPixels(f1);
    paramCanvas.drawCircle(localPoint.x, localPoint.y, f2, this.l);
  }

  public boolean enableCompass()
  {
    this.j = Mj.b.a(this);
    return this.j;
  }

  public boolean enableMyLocation()
  {
    Mj.b.requestLocationUpdates(this);
    this.a = Mj.b.getLocationInfo();
    if (this.a != null)
    {
      this.b = new GeoPoint(this.a.getLatitude(), this.a.getLongitude());
      this.c = GetBaidu09Point(this.b, Mj.c);
    }
    this.i = true;
    this.e.invalidate();
    return true;
  }

  public Location getLastFix()
  {
    return this.a;
  }

  public GeoPoint getMyLocation()
  {
    return this.b;
  }

  public float getOrientation()
  {
    return this.k;
  }

  public boolean isCompassEnabled()
  {
    return this.j;
  }

  public boolean isMyLocationEnabled()
  {
    return this.i;
  }

  public void onAccuracyChanged(Sensor paramSensor, int paramInt)
  {
  }

  public void onLocationChanged(Location paramLocation)
  {
    this.a = paramLocation;
    if (this.a == null)
    {
      this.b = null;
      this.c = null;
      this.e.invalidate();
    }
    do
    {
      return;
      this.b = new GeoPoint(paramLocation.getLatitude(), paramLocation.getLongitude());
      this.c = GetBaidu09Point(this.b, Mj.c);
      this.e.invalidate();
    }
    while (this.d == null);
    this.d.run();
    this.d = null;
  }

  public void onProviderDisabled(String paramString)
  {
    this.i = false;
  }

  public void onProviderEnabled(String paramString)
  {
    this.i = true;
  }

  public void onSensorChanged(SensorEvent paramSensorEvent)
  {
    int m;
    if (paramSensorEvent.sensor.getType() == 3)
    {
      m = (int)paramSensorEvent.values[0];
      if (this.e.getResources().getConfiguration().orientation == 2)
        m = (m + 90) % 360;
      if (Math.abs(m - this.k) >= 10.0F)
      {
        this.k = m;
        if (this.e.b != null)
          break label79;
      }
    }
    return;
    label79: this.e.b.b = m;
    this.e.invalidate();
  }

  public boolean onSnapToItem(int paramInt1, int paramInt2, Point paramPoint, MapView paramMapView)
  {
    return false;
  }

  public boolean onTap(GeoPoint paramGeoPoint, MapView paramMapView)
  {
    GeoPoint localGeoPoint = getMyLocation();
    Point localPoint1;
    if (localGeoPoint != null)
    {
      localPoint1 = this.e.getProjection().toPixels(localGeoPoint, null);
      if (this.f != null)
        break label34;
    }
    label34: Rect localRect;
    Point localPoint2;
    do
    {
      return false;
      int m = this.f.getWidth() / 2;
      int n = this.f.getHeight() / 2;
      localRect = new Rect(localPoint1.x - m, localPoint1.y - n, m + localPoint1.x, n + localPoint1.y);
      localPoint2 = this.e.getProjection().toPixels(paramGeoPoint, null);
    }
    while (!localRect.contains(localPoint2.x, localPoint2.y));
    return dispatchTap();
  }

  public boolean runOnFirstFix(Runnable paramRunnable)
  {
    if (this.a != null)
    {
      paramRunnable.run();
      return true;
    }
    this.d = paramRunnable;
    return false;
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.baidu.mapapi.MyLocationOverlay
 * JD-Core Version:    0.6.2
 */